﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shop.Home.Services
{
    /// <summary>
    /// /// <summary>
    /// 生成订单时对商品的操作业务逻辑层
    /// </summary>
    /// </summary>
    public class WaresInventoryAccess
    {

        Shop.Home.Repositories.WaresInventoryAccess dal = new Repositories.WaresInventoryAccess();
        /// <summary>
        /// 根据商品ID获取商品库存
        /// </summary>
        /// <param name="WID"></param>
        /// <returns>返回0有库存，返回1没库存</returns>
        public int GetWaresStock(int WID,int BuyNum)
        {
            int Stock = dal.GetWaresStock(WID).Stock;
            if (BuyNum > Stock)
            {
                return 1;
            }
            return 0;
        }
        /// <summary>
        /// 减少商品库存
        /// </summary>
        /// <param name="WID">商品ID</param>
        /// <param name="BuyNum">减少的数量</param>
        /// <returns></returns>
        public int ReduceWares(int WID, int BuyNum)
        {
            return dal.ReduceWares(WID, BuyNum);
        }
        /// <summary>
        /// 增加商品销量
        /// </summary>
        /// <param name="WID"></param>
        /// <param name="BuyNum"></param>
        /// <returns></returns>
        public int AddSaleNum(int WID, int BuyNum)
        {
            return dal.AddSaleNum(WID,BuyNum);
        }
    }
}
